package com.ruoyi.labdata.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.labdata.domain.LabRestrictedProperty;
import com.ruoyi.labdata.service.ILabRestrictedPropertyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 管控品属性Controller
 * 
 * @author winner pan
 * @date 2022-02-16
 */
@RestController
@RequestMapping("/labdata/restrictedProperty")
public class LabRestrictedPropertyController extends BaseController {
	@Autowired
	private ILabRestrictedPropertyService labRestrictedPropertyService;

	/**
	 * 查询管控品属性列表
	 */
	@PreAuthorize("@ss.hasPermi('labdata:restrictedProperty:query')")
	@GetMapping("/list")
	public TableDataInfo list(LabRestrictedProperty labRestrictedProperty) {
		startPage();
		List<LabRestrictedProperty> list = labRestrictedPropertyService
				.selectLabRestrictedPropertyList(labRestrictedProperty);
		return getDataTable(list);
	}

	/**
	 * 导出管控品属性列表
	 */
	// @PreAuthorize("@ss.hasPermi('labdata:restrictedProperty:export')")
	/*
	 * @Log(title = "管控品属性", businessType = BusinessType.EXPORT)
	 * 
	 * @GetMapping("/export") public AjaxResult export(LabRestrictedProperty
	 * labRestrictedProperty) { List<LabRestrictedProperty> list =
	 * labRestrictedPropertyService.selectLabRestrictedPropertyList(
	 * labRestrictedProperty); ExcelUtil<LabRestrictedProperty> util = new
	 * ExcelUtil<LabRestrictedProperty>(LabRestrictedProperty.class); return
	 * util.exportExcel(list, "restrictedProperty"); }
	 */

	/**
	 * 获取管控品属性详细信息
	 */
	@PreAuthorize("@ss.hasPermi('labdata:restrictedProperty:query')")
	@GetMapping(value = "/{propertyId}")
	public AjaxResult getInfo(@PathVariable("propertyId") Long propertyId) {
		return AjaxResult.success(labRestrictedPropertyService.selectLabRestrictedPropertyById(propertyId));
	}

	/**
	 * 新增管控品属性
	 */
	@PreAuthorize("@ss.hasPermi('labdata:restrictedProperty:edit')")
	@Log(title = "管控品属性", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody LabRestrictedProperty labRestrictedProperty) {
		return toAjax(labRestrictedPropertyService.insertLabRestrictedProperty(labRestrictedProperty));
	}

	/**
	 * 修改管控品属性
	 */
	@PreAuthorize("@ss.hasPermi('labdata:restrictedProperty:edit')")
	@Log(title = "管控品属性", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody LabRestrictedProperty labRestrictedProperty) {
		return toAjax(labRestrictedPropertyService.updateLabRestrictedProperty(labRestrictedProperty));
	}

	/**
	 * 删除管控品属性
	 */
	@PreAuthorize("@ss.hasPermi('labdata:restrictedProperty:edit')")
	@Log(title = "管控品属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{propertyIds}")
	public AjaxResult remove(@PathVariable Long[] propertyIds) {
		return toAjax(labRestrictedPropertyService.deleteLabRestrictedPropertyByIds(propertyIds));
	}
}
